package com.ss.android.newmedia;

import android.os.Looper;
import android.text.TextUtils;

import com.ss.android.common.applog.AppLog;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

public final class k {
    private static final ReentrantLock a;
    private static final Condition b;
    private static boolean c;

    static {
        ReentrantLock v0 = new ReentrantLock();
        a = v0;
        b = v0.newCondition();
        c = false;
    }

    public static boolean a() {
        boolean v0 = true;
        if (!k.c) {
            k.a.lock();
            try {
                if (TextUtils.isEmpty(AppLog.deviceId())) {
                    if (!k.b.await(4000, TimeUnit.MILLISECONDS)) {
                        return false;
                    }

                    if (TextUtils.isEmpty(AppLog.deviceId())) {
                        v0 = false;
                        k.c = v0;
                        return v0;
                    }

                    k.c = v0;
                    return v0;
                }
                return v0;
            } catch (InterruptedException v0_1) {
                v0_1.printStackTrace();
            } finally {
                k.a.unlock();
            }
            v0 = false;
        }

        return v0;
    }

    public static void b() {
        k.e();
        k.a.tryLock();
    }

    public static void c() {
        k.e();
        try {
            k.a.unlock();
        } catch (IllegalMonitorStateException v0) {
            v0.printStackTrace();
        }
    }

    public static void d() {
        if (!k.c) {
            k.a.lock();
            try {
                k.b.signalAll();
            } catch (IllegalMonitorStateException v0_1) {
                v0_1.printStackTrace();
            } finally {
                k.a.unlock();
            }
        }
    }

    private static void e() {
        if (Thread.currentThread() != Looper.getMainLooper().getThread()) {
            throw new RuntimeException("Only main thread can call this method.");
        }
    }
}

